*! version 0.1.0 30Apr2016
*
*  Write estimation results to file

program define writemodel
    version 14
    syntax [anything] using/, [drop(passthru) order(passthru) EXTensions(namelist)]

    if "`extensions'" == "" {
        // default extension is rtf
        loc extensions = "rtf"
    }

    foreach ext in `extensions' {
        loc fpath = "`using'.`ext'"

        if ("`ext'" != "tex") {

            qui esttab `anything' using `fpath', replace nogap noomit label  /*
                */ nodep `drop' varwidth(20) b(3) se(3) parentheses          /*
                */ star(* .10 ** .05 *** .01) stardetach `order'             /*
                */ stats(sfix yfix trnd N ll k, fmt(0 0 0 0 0 0)             /*
                */       labels("State FE" "Year FE" "State Trend" "N" "LL" "K"))
        }
        else {  // latex table

            qui esttab `anything' using `fpath', replace booktabs nogap     /*
                */ noomit label nonotes nomti nodep interact(" $\times$ ")  /*
                */ b(3) se(3) parentheses star(* .10 ** .05 *** .01)        /*
                */ stardetach `drop' `order'                                /*
                */ stats(sfix yfix trnd N ll k, fmt(0 0 0 0 0 0)            /*
                */       labels("State FE" "Year FE" "State Trend" "N" "LL" "K"))
        }
        di as result "Saved models to `fpath'"
    }
end
